package com.example.smartmallserver.demos.web.controller;

import com.example.smartmallserver.demos.web.pojo.Goods;
import com.example.smartmallserver.demos.web.service.IndexService;
import com.example.smartmallserver.demos.web.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@CrossOrigin
@RestController
public class SearchController {
    @Autowired
    IndexService indexService;
    @GetMapping("/goods/list")
    Result gethGoodsByName(  Goods goods ){
        System.out.println("goods:  "+goods);
        if (goods.getName()!=null){
            List<Goods> goods1 = indexService.getGoodsByName(goods.getName());
            return Result.success(goods1);
        } else if (goods.getCategoryId()!=null) {
            List<Goods> goods1 = indexService.getGoodsByCategoryId(goods.getCategoryId());
            return Result.success(goods1);
        }
        return Result.error();
    }

}
